//
//  Test16.cpp
//  CPPTest
//
//  Created by changqing.chen on 2021/9/24.
//

#include "Test16.hpp"
#include <iostream>
#include <string>

using namespace std;

class str3 {
    
    string s;
    int n,a[100],j,l;
    
    public:
    str3(string&a) {
        s=a;n=0;j=0;l=0;
    }
    void test();
    int *geta() {
        return a;
    }
    int getn() {
        return n;
    }
};

inline void str3::test() {
    int k = 0;
    for (int i=0; i<s.size(); i++) {
        if (s[i]==' '&&i!=0) {
            a[n] = k;
            n++;
            k = i+1;
        }
    }
    if (s[s.size()-1] != ' ') {
        a[n] = k;
        n++;
    }
    cout<<"单词个数："<<this->getn()<<endl;
    cout << "单词索引：";
    for (int i = 0; i < n; i++)
    {
        cout << this->a[i] << " ";
    }
    cout << endl;
}

void test16() {
    string strvalue = "i love you, and you? 哈哈";
    str3 s = str3(strvalue);
    s.test();
}

